package server;





import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;

import utils.DBManager;
import utils.UserData;

public class DefaultUsersManager implements UsersManager {

	private SortedMap<String, UserData> userData = Collections.synchronizedSortedMap(new TreeMap<String, UserData>());

	
	public DefaultUsersManager () {
	}
	

	@Override
	public void addUser(UserData user) {
		userData.put((String) user.getProperty("address"), user);
	}

	@Override
	public void removeUser(String key) {
		userData.remove(key);
	}

	@Override
	public UserData getUser(String address) {
		return userData.get(address);
	}

	@Override
	public UserData getUserCopy(int address) {
		return userData.get(address).clone();
	}

	@Override
	public SortedMap<String, UserData> getUsers() {
		return userData;
	}


	@Override
	public void closeDataSource() {
		DBManager.closeConnection();
	}

	

}
